"""
https://tieba.baidu.com/p/7437709591
抓取帖子中的视频
"""
import requests
from lxml import etree
from fake_useragent import UserAgent

# 1.定义常用变量
url = 'https://tieba.baidu.com/p/7437709591'
headers = {'User-Agent':UserAgent(path='fake_useragent.json').random}
# 2.提取视频链接
html = requests.get(url=url, headers=headers).text
eobj = etree.HTML(html)

src_list = eobj.xpath('//embed/@data-video')
if src_list:
    video_url = src_list[0]
    # 保存视频
    html = requests.get(url=video_url, headers=headers).content
    with open('颖火虫.mp4', 'wb') as f:
        f.write(html)
else:
    print('未提取到视频链接')





























